package com.zzgele.qmzb.api.web;

import com.alibaba.boot.dubbo.annotation.DubboConsumer;
import com.github.pagehelper.PageInfo;
import com.zzgele.qmzb.api.core.Result;
import com.zzgele.qmzb.api.core.ResultGenerator;
import com.zzgele.qmzb.api.model.User;
import com.zzgele.qmzb.api.service.UserService;
import com.zzgele.qmzb.api.utils.PageUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
* Created by Martin on 2017/07/09.
*/
@RestController
@RequestMapping("/test")
public class TestController {
    private final Logger logger = LoggerFactory.getLogger(TestController.class);
    @DubboConsumer
    private UserService userService;

    @RequestMapping("/list")
    public Result list(Integer page, Integer page_size) {
        PageUtil.startPage(page, page_size);
        List<User> list = userService.findAll();
        HashMap userListHashMap = PageUtil.getPageInfoHashMap(new PageInfo(list));
        return ResultGenerator.genSuccessResult(userListHashMap);
    }

    @RequestMapping("/success")
    public Result success() {
        return ResultGenerator.genSuccessResult();
    }

    @RequestMapping("/fail")
    public Result fail() {
        return ResultGenerator.genFailResult("fail");
    }
}
